﻿namespace Microsoft.SharePoint.Client
{
    using System;
    using System.ComponentModel;

    [ScriptType("SP.NavigationNodeCollection", ServerTypeId="{2d818ed7-8fef-4a1c-bceb-a9404dfa482f}")]
    public class NavigationNodeCollection : ClientObjectCollection<NavigationNode>
    {
        [EditorBrowsable(EditorBrowsableState.Never)]
        public NavigationNodeCollection(ClientRuntimeContext Context, ObjectPath ObjectPath) : base(Context, ObjectPath)
        {
        }

        [Remote]
        public NavigationNode Add(NavigationNodeCreationInformation parameters)
        {
            if (base.Context.ValidateOnClient)
            {
                if (parameters == null)
                {
                    throw ClientUtility.CreateArgumentNullException("parameters");
                }
                if (((parameters != null) && (parameters.Title != null)) && (parameters.Title.Length > 0x100))
                {
                    throw ClientUtility.CreateArgumentException("parameters.Title");
                }
            }
            NavigationNode node = new NavigationNode(base.Context, new ObjectPathMethod(base.Context, base.Path, "Add", new object[] { parameters }));
            node.Path.SetPendingReplace();
            ObjectIdentityQuery query = new ObjectIdentityQuery(node.Path);
            base.Context.AddQueryIdAndResultObject(query.Id, node);
            base.Context.AddQuery(query);
            base.AddChild(node);
            node.InitFromCreationInformation(parameters);
            return node;
        }

        protected override bool InitOnePropertyFromJson(string peekedName, JsonReader reader)
        {
            bool flag = base.InitOnePropertyFromJson(peekedName, reader);
            if (flag)
            {
                return flag;
            }
            return flag;
        }
    }
}

